package hk.edu.polyu.comp.motioncapture.analysis.sequence;

import hk.edu.polyu.comp.motioncapture.collection.*;
import hk.edu.polyu.comp.motioncapture.point.*;

public class PointTrack {
	DimensionGeometry dimGeo = new DimensionGeometry();
	public static Frame staticPointFrame;
	public static Frame dynamicPointFrame;

	/**
	 * @deprecated Developing in progress
	 * @param pt
	 * @return
	 */
	public boolean isStaticPoint(Point pt) {
		return false;
	}

	/**
	 * @deprecated
	 * @param optiPointVc
	 * @param tolerance
	 * @return
	 */
	public static void findStaticPoints(FrameSet optiPointVc, int tolerance) {
		// return analyisiStaticDynamicPoints(optiPointVc, tolerance, 1);
	}

	/**
	 * @deprecated
	 * @param optiPointVc
	 * @param tolerance
	 * @return
	 */
	public static void findDynamicPoints(FrameSet optiPointVc, int tolerance) {
		// return analyisiStaticDynamicPoints(optiPointVc, tolerance, 2);
	}

	public static void analyisiStaticDynamicPoints(FrameSet frameSet,
			int tolerance) {

		staticPointFrame = new Frame();
		dynamicPointFrame = new Frame();

		Frame firstFrame = frameSet.first();
		Frame lastFrame = frameSet.last();

		// Assume all point are static point, compare distance between
		// each pair of point, if the distance between one pair of point
		// is less than tolerance, the point is static
		for (int i = 0; i < lastFrame.size(); i++) {
			boolean isOnePairOfPtLessThanTol = false;

			for (int j = 0; j < firstFrame.size(); j++) {
				if (DimensionGeometry.withinDistance(lastFrame.pointAt(i),
						firstFrame.pointAt(j), tolerance)) {
					isOnePairOfPtLessThanTol = true;
					break;
				}
			}

			if (isOnePairOfPtLessThanTol)
				staticPointFrame.add(lastFrame.pointAt(i));
			else
				dynamicPointFrame.add(lastFrame.pointAt(i));
		}
	}

	public static Point[] sortingPointY(Frame inputPointVc) {
		Point[] ptObjArr = inputPointVc.getPointArray();

		Point.sortPointByY(ptObjArr);

		return ptObjArr;
	}

	public static Point[] sortingPointX(Frame inputPointVc) {
		Point[] ptObjArr = inputPointVc.getPointArray();
		
		Point.sortPointByX(ptObjArr);

		return ptObjArr;
	}

	public static boolean isInRegion(int tolerance, Point checkPt,
			Point referPt) {
		return DimensionGeometry.withinDistance(checkPt, referPt, tolerance);
	}
}
